Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 Search this book:
Previous | Table of Contents | Next
## Chapter 3 Drawing Your Way To Success One of the revolutionary innovations that Visual Basic brought to programming was the ability to draw your program’s visual interface. In this chapter, I’ll show you the techniques of visual interface design. The first two chapters introduced you to some of the concepts and theory behind Visual Basic and guided you through creating and running your first project. Hopefully, you’re excited and eager to dig in, because we’ve just begun to scratch the surface. Now it’s time to learn more about objects and properties. I cannot overemphasize the close relationship between objects and properties. They really can’t be separated—an object is its properties, to a very large degree. To derive the most from Visual Basic’s objects, you need to develop an intimate knowledge of their properties. And because objects are central to the whole idea of Visual Basic programming...well, you get the idea. Let’s begin with the fundamentals of starting and opening Visual Basic projects, saving files, and other basic tasks. From there, we will explore the tools and techniques that Visual Basic provides for visual interface design. Next, we’ll explore properties, and finally, we’ll work through a demonstration project to illustrate these concepts. ### Working With Projects Every time you start Visual Basic, you’ll do one of two things: begin a new project or open a project that already exists. Either of these tasks can be accomplished in the New Project dialog box. This dialog box is normally displayed when you start Visual Basic. As shown in Figure 3.1, this dialog box has three tabs with the following functions: • New—Use this tab to start a new project based on one of Visual Basic’s project types (to be explained in a future chapter). For now, you will be using the default type, Standard EXE. • Existing—Use this tab to locate an existing Visual Basic project on disk and open it. • Recent—This tab lists Visual Basic projects that you have worked on recently, permitting you to select one to open. Note that the New Project dialog box has a Don’t Show This Dialog in the Future checkbox. If you turn this option on, the dialog box will not be displayed when Visual Basic is started. Instead, a new Standard EXE project will be created as a default. If you have selected this option and want to re-enable display of the New Project dialog box when Visual Basic starts, follow these steps: 1. Select Options from the Tools menu to display the Options dialog box. 2. Click the Environment tab. Figure 3.1 The New Project dialog box is displayed when you start Visual Basic. 3. In the When Visual Basic Starts section, turn on the Prompt for Project option. 4. Click on OK. If the New Project dialog box is not displayed when you start Visual Basic, you start a new project by selecting New Project from the File menu. To open a recent project, open the File menu and select from the list displayed near the bottom of the menu. To select a project from disk, select File|Open Project or press Ctrl+O to display the Open dialog box. ### Understanding Modules Every Visual Basic project contains at least one module, and a complex project may contain a dozen or more. Each module in a project is saved to disk in its own file. The file gets a name that you assign and an extension that identifies the type of module. The most important type of module is the form module, corresponding to one form or window in your project. With rare specialized exceptions, every Visual Basic project contains at least one form module. Form module files are given the .FRM extension. Another type of module you will frequently use is simply called module, although I prefer to use the term code module, because it contains only Basic code and no visual elements. Code module files are given the .BAS extension. There are some other types of modules, and we will deal with them as the need arises. ### Saving Projects Each Visual Basic project consists of at least two separate parts that must be saved to disk if you want to preserve them. First are one or more modules, as described in the previous section. You can have multiple form and code modules open at the same time, but only one of them will be current—the one you are working on at the moment (as selected in the Project Explorer window). To save the active module, press Ctrl+S or select Save XXX from the File menu (XXX representing the name of the module). When you save a module for the first time, Visual Basic suggests a default name for it. In the case of form modules, this is the form’s Name property, which, if you have not changed it, will be a default name—Form1, Form2, etc. For code modules, the default name is Module1, etc. The first time you save a module, you will be prompted for a file name, with this default name suggested by Visual Basic. If you have assigned your form a meaningful Name property that is descriptive of its function (and you should do so), then accepting this name is perfectly fine. You can also assign another name, but be sure to assign a name that actually helps you identify the module. If you have multiple modules, you need to save each one individually. Fortunately, Visual Basic will help avoid lost data by reminding you to save modules, if they have not already been saved, before quitting the project. Once you assign a name to a module, selecting File|Save or pressing Ctrl+S will save the current version of the module under the original name without prompting. If you want to assign a new file name to a module that has already been saved, select Save XXX As from the File menu (again, XXX is the current name of the module). TIP: Module Name Confusion It’s easy to get a bit confused about Visual Basic module names, because most modules have two names: the Name property that you assign to the module in the Properties window, and the file name that you assign when you save the module. These two names can be the same, but do not have to be. Code modules are the one exception, as they do not have a Name property and so have only a file name. In the Project Explorer window, form modules are listed with both their Name property and, in parentheses, their file name. The second part of a Visual Basic project that needs to be saved is the project itself. This project file does not contain any forms or code, but rather identifies the modules in the project, the current Visual Basic environment settings, and so on. When you load an existing project, you are loading this project file; Visual Basic, in turn, uses the information in the project file to load the component modules. Project files receive the .VBP extension.
Previous | Table of Contents | Next

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.